#ifndef ITERATORDICTIONARY_H_INCLUDED
#define ITERATORDICTIONARY_H_INCLUDED

namespace CEngine {

template<class E, class K>
Iterator<E,K>::Iterator(const typename Dictionary<E,K>::DictionaryIterator& it)
    :   type(Dictionary)
{
    iteratorData.dictionary.basePointer = it.basePointer;
    iteratorData.dictionary.currentNode = it.currentPointer;
    iteratorData.dictionary.currentElement = &iteratorData.dictionary.currentNode->element;
    iteratorData.dictionary.currentKey = iteratorData.dictionary.currentNode->key;
}

template<class E, class K>
Iterator<E,K>&
Iterator<E,K>::operator=(const typename Dictionary<E,K>::DictionaryIterator& it) {
    type = Dictionary;
    iteratorData.dictionary.basePointer = it.basePointer;
    iteratorData.dictionary.currentNode = it.currentPointer;
    iteratorData.dictionary.currentElement = &iteratorData.dictionary.currentNode->element;
    iteratorData.dictionary.currentKey = iteratorData.dictionary.currentNode->key;
    return *this;
}

template<class E, class K>
bool Iterator<E,K>::operator==(const typename Dictionary<E,K>::DictionaryIterator& it) const {
    ASSERT(type == Dictionary);

    if(iteratorData.dictionary.currentNode == it.currentPointer) {
        return true;
    }
    return false;
}

template<class E, class K>
bool Iterator<E,K>::operator!=(const typename Dictionary<E,K>::DictionaryIterator& it) const {
    ASSERT(type == Dictionary);

    if(iteratorData.dictionary.currentNode != it.currentPointer) {
        return true;
    }
    return false;
}

template<class E, class K>
bool Iterator<E,K>::operator>(const typename Dictionary<E,K>::DictionaryIterator& it) const {
    ASSERT(type == Dictionary && iteratorData.dictionary.basePointer == it.basePointer);

    if(iteratorData.dictionary.currentNode > it.currentPointer) {
        return true;
    }
    return false;
}

template<class E, class K>
bool Iterator<E,K>::operator<(const typename Dictionary<E,K>::DictionaryIterator& it) const {
    ASSERT(type == Dictionary && iteratorData.dictionary.basePointer == it.basePointer);

    if(iteratorData.dictionary.currentNode < it.currentPointer) {
        return true;
    }
    return false;
}

template<class E, class K>
bool Iterator<E,K>::operator>=(const typename Dictionary<E,K>::DictionaryIterator& it) const {
    ASSERT(type == Dictionary && iteratorData.dictionary.basePointer == it.basePointer);

    if(iteratorData.dictionary.currentNode >= it.currentPointer) {
        return true;
    }
    return false;
}

template<class E, class K>
bool Iterator<E,K>::operator<=(const typename Dictionary<E,K>::DictionaryIterator& it) const {
    ASSERT(type == Dictionary && iteratorData.dictionary.basePointer == it.basePointer);

    if(iteratorData.dictionary.currentNode <= it.currentPointer) {
        return true;
    }
    return false;
}

template<class E, class K> inline
E* Iterator<E,K>::dictionaryRandomAccess(K key) {
    iteratorData.dictionary.currentNode = iteratorData.dictionary.basePointer->search(key);
    iteratorData.dictionary.currentElement = &iteratorData.dictionary.currentNode->element;
    iteratorData.dictionary.currentKey = &iteratorData.dictionary.currentNode->key;
    return iteratorData.dictionary.currentElement;
}

}

#endif // ITERATORDICTIONARY_H_INCLUDED
